import _ from 'lodash';
import { Parameter } from '../entities/parameter';
import { EntityRepository, Repository } from 'typeorm';

export interface IParameterRepository {
  findByProduct(productName: string): Promise<Parameter[]>;
  findByProductAndName(productName: string, parameterName: string): Promise<Parameter>;
}

@EntityRepository(Parameter)
export class ParameterRepository extends Repository<Parameter> implements IParameterRepository {

  async findByProduct(productName: string): Promise<Parameter[]> {
    return await this.find({ where: { product: productName } });
  }
  
  async findByProductAndName(productName: string, parameterName: string): Promise<Parameter> {
    return this.findOne({ where: { product: productName, name: parameterName } });
  }
}